<!--高顺-->
<!DOCTYPE html>
<!-- suppress ThymeleafVariablesResolveInspection -->
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="description" content="A admin dashboard application demo built upon Ant Design and Dva.js">
    <title>南瓜课堂登录</title>
    <script th:src="@{/static/js/login.js}"></script>
    <link rel="stylesheet" th:href="@{/static/css/index.css}">
    <link rel="stylesheet" th:href="@{/static/layui/css/layui.css}">
</head>
<style>
    .layui-form-item {
        margin-left: -20px;
    }

    a:hover {
        text-decoration: underline;
    }

    .layui-form-item {
        margin: auto;
        width: 315px !important;
        height: 49px;
        border: none;
        padding: 2px 0;
        position: relative;
        border-radius: 3px;
        margin: 10px auto;
        line-height: 49px;
        display: -ms-flexbox;
        display: flex;
    }

    .layui-input-block {
        margin-left: 20px;
        line-height: 43px;
    }

    .layui-form-radio {
        margin: 6px -3px 0 0;
    }
</style>
<body>
<div class="root" id="code">

    <div class="loginPop___1CsFh" version="3.3.4">
        <div class="loginBox___2Xt6j">
            <div class="logintitle___1W8YV">
                <div>欢迎来到南瓜课堂</div>
                <div class="registerpondx___e-_hU" th:onclick="window.parent.yincang()">
                    <img src="https://www-cdn-res.shiguangkey.com/res/images/x-black.png"
                         alt="">
                </div>
            </div>
            <div class="swith___1FNx-">
                <div class="loginNav___2o18r">
                </div>
                <div class="account___2IrJR">
                    <div class="acc-input mtop25 layui-form">
                        <div class="acountBox___1YcKn acctype">
                            <input type="text" class="atin___1pcep" id="userPhone" name="userPhone"
                                   placeholder="请输入账号">
                        </div>
                        <div class="acctype">
                            <input type="password" class="atin___1pcep" id="userPwd" name="userPwd"
                                   placeholder="请输入密码">
                        </div>
                        <div class="layui-form-item">
                            <a class="fl item-pss" style="cursor: pointer;text-decoration: none">选择身份</a>
                            <div class="layui-input-block">
                                <input type="radio" id="ck_user" name="c1" value="用户登录" title="用户" checked/>
                                <input type="radio" d="ck_teacher" name="c1" value="讲师登录" title="讲师"/>
                                <input type="radio" d="ck_admin" name="c1" value="管理员登录" title="管理员"/>
                            </div>
                        </div>
                        <div class="item-member">
                            <a class="fl item-pss" style="cursor: pointer;">免费注册</a>
                            <a class="fr item-pss" href="" target="_black" style="cursor: pointer;">忘记密码?</a>
                        </div>
                        <button class="loginButton___1GO7F layui-btn layui-btn-radius" type="button" id="but">立即登录
                        </button>
                        <div class="clear"></div>
                    </div>
                </div>
                <div>
                    <div class="gantitle___1Bo_m"><span class="gttxt___1vaWe">快速登录</span></div>
                    <div class="ganerBut___fOt-k"><span id="weixinLogin" class="undefined undefined"><img
                            src=""
                            alt=""></span><span id="qqLogin"><img
                            src=""
                            alt=""></span></div>
                </div>
            </div>
        </div>

    </div>


</div>

<div class="acc-error" id="error-tips" style="display: none; margin-left: -130px;"><span>对不起，账号或密码错误</span></div>
<script th:src="@{/static/js/jquery-1.8.3.js}"></script>
<script type="text/javascript" th:src="@{/static/js/index.js}"></script>
<script type="text/javascript" th:src="@{/static/layui/layui.js}"></script>
<script>
    layui.use(['form', 'layedit', 'laydate'], function () {
        var form = layui.form;
        form.render();
    });


    /*倒计时显示提示内容*/
    function tishi(content) {
        if ($('#error-tips').css('display') === 'none') {
            var num = 3;
            var s = setInterval(function () {
                $("#error-tips").css("display", "block");
                $("#error-tips span").html(content);
                num--;
                if (num <= 0) {
                    $("#error-tips").css("display", "none");
                    clearInterval(s);
                }
            }, 1000);
        }
    }

    /*账号密码不能为空验证*/
    //登录密码验证
    function pwdCheck() {
        var userPwd = $("#userPwd").val().trim();
        if (userPwd == '') {
            tishi("密码不能为空")
            return false;
        } else {
            return true;
        }
    }

    //登录密码验证
    function phoneCheck() {
        var userPwd = $("#userPhone").val().trim();
        if (userPwd == '') {
            tishi("账号不能为空")
            return false;
        } else {
            return true;
        }
    }


    // 验证手机号和邮箱是否正确
    // 登录手机号邮箱验证
    function checkPhoneRegister() {
        var phone = $("#userPhone").val().trim();
        var checkPhone = true;
        $.ajax({
            url: '/user/phoneIsRegYesOrNo',
            dataType: 'json',
            type: 'post',
            async: false,
            data: {
                userPhone: phone
            }, success: function (data) {
                if (data.msg != "ok") {
                    tishi("该手机号还未注册或已被禁用！");
                    checkPhone = false;
                }
            }
        });
        return checkPhone;
    }


    /*用户登录*/
    function userLogin(gphone, password) {
        var flag = true;
        if (checkPhoneRegister()) {
            $.ajax({
                url: '/user/phoneLoginDes',
                type: 'post',
                async: false,
                dataType: 'json',
                data: {
                    gphone: gphone,
                    password: password
                }, success: function (data) {
                    if (data.msg == "ok") {
                        window.parent.getSession();
                        window.parent.yincang();
                    } else {
                        tishi('对不起，账号或者密码错误');
                        flag = false
                    }
                }
            })
        }
        return flag;
    }

    /*讲师登录*/
    function teacherLogin(gphone, password) {
        var flag = true;
        $.ajax({
            url: '/teacherPhoneLoginDes',
            type: 'post',
            async: false,
            dataType: 'json',
            data: {
                gphone: gphone,
                password: password,
            }, success: function (data) {
                if ((data.msg) == "该用户不是讲师用户！") {
                    tishi("该用户不是讲师用户！请确认手机号/邮箱/密码是否正确");
                    flag = false;
                } else {
                    window.parent.getTeacherSession();
                    window.parent.yincang();
                }
            }
        })
        return flag;
    }


    /*讲师登录*/
    function adminLogin(gphone, password) {
        var flag = true;
        $.ajax({
            url: '/teacherPhoneLoginDes',
            type: 'post',
            async: false,
            dataType: 'json',
            data: {
                gphone: gphone,
                password: password,
            }, success: function (data) {
                if ((data.msg) == "该用户不是讲师用户！") {
                    tishi("该用户不是讲师用户！请确认手机号/邮箱/密码是否正确");
                    flag = false;
                } else {
                    window.parent.getTeacherSession();
                    window.parent.yincang();
                }
            }
        })
        return flag;
    }


    // 登录按钮
    $("#but").click(function () {
        var a = $("input[name='c1']:checked").val();
        var phoned = $("#userPhone").val();
        var pwdd = $("#userPwd").val();
        var phoneIsNull = phoneCheck();
        var pwdIsNull = pwdCheck();
        if(phoneIsNull && pwdIsNull){
            if (a == "用户登录") {
                userLogin(phoned,pwdd);
            } else if (a == "讲师登录") {
                teacherLogin(phoned,pwdd);
            }else if(a == "管理员登录"){
                adminLogin(phoned,pwdd);
            }
        }

    });


</script>
</body>
</html>